package leetcode;

import org.junit.Test;

/**
 * @author cino
 * justCode
 */
public class leetcode74 {

    @Test
    public void test(){
        int[][] matrix = {{1,3,5,7},{10,11,16,20},{23,30,3,60}};
        int target = 7;
        System.out.println(searchMatrix(matrix, target));
    }


    public static boolean searchMatrix(int[][] matrix, int target) {
        int rows = matrix.length - 1, columns = 0;
        while (rows >= 0 && columns < matrix[0].length) {
            int num = matrix[rows][columns];
            if (num == target) {
                return true;
            } else if (num > target) {
                rows--;
            } else {
                columns++;
            }

        }
        return false;
    }
}
